package com.example.light.web.meeting.controller;

import com.example.light.web.meeting.entity.OaMachine;
import com.example.light.web.meeting.service.OaMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MachineController {
    @Autowired
    private OaMachineService machineService;

    private  OaMachine editMachine;
    @RequestMapping("addMachine")
    @ResponseBody
    String addMachine(OaMachine machine, BindingResult result){
        try {
            machineService.addMachine(machine);
            return "成功";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "错误";
    }

    @RequestMapping("toEditMachine")
    String toEditMachine(OaMachine machine, BindingResult result, Model model){
        if (machine.getmId() != null) {
            editMachine = machineService.querySingle(machine.getmId(), model);
            return "meeting/meet_room/device_modify";
        }
        machineService.addModel(model, editMachine);
        return "meeting/meet_room/device_modify";
    }

    @RequestMapping("editMachine")
    @ResponseBody
    String editMachine(OaMachine machine,BindingResult result){
        try {
            machineService.editMachine(machine);
            return "成功";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "失败";
    }

    @RequestMapping("delMachine")
    @ResponseBody
    String delMachine(int[] delInfo){
        try {
            machineService.delMachine(delInfo);
            return "成功";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "失败";
    }
}
